var allpoint=null;
$(function () {
    $.when( $.get(baseURL + 'bss/dpoint/select?pGuid='+ GetUrlParam("guid"), function (r) {
            allpoint = r.returnlist;
        })

    ).done(
    $("#jqGrid").jqGrid({
        url: baseURL + 'bss/ddrawline/list?pGuid='+ GetUrlParam("guid"),
        datatype: "json",
        colModel: [			
			{ label: 'guid', name: 'guid', index: 'guid', width: 50, key: true , hidden: true},
			{ label: '所属项目ID', name: 'pGuid', index: 'p_guid', width: 80 , hidden: true},
			{ label: '所属点位ID', name: 'pPGuid', index: 'p_p_guid', width: 80,
                formatter: function (cellvalue, options, rowObject) {
                    for (d in allpoint) {
                        if (cellvalue == allpoint[d].guid) return allpoint[d].pPCode;
                    }
                }

			},
			{ label: '拉线类别', name: 'dLType', index: 'd_l_type', width: 80 },
			{ label: '经度', name: 'dLLongitude', index: 'd_l_longitude', width: 80 },
			{ label: '纬度', name: 'dLLatitude', index: 'd_l_latitude', width: 80 }, 			
			{ label: '拉线坑土质', name: 'dLSoil', index: 'd_l_soil', width: 80 }, 			
			{ label: '坑深', name: 'dLDeep', index: 'd_l_deep', width: 80 }, 			
			{ label: '采集时间', name: 'dLCollecttime', index: 'd_l_collecttime', width: 80 ,
                formatter:function(value,options,row){
                    return value!=null?new Date(value).Format('yyyy-MM-dd'):"";}
			}
	  ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    })
	)
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		dDrawLine: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.dDrawLine = {};
		},
		update: function (event) {
			var guid = getSelectedRow();
			if(guid == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(guid)
		},
		saveOrUpdate: function (event) {
			var url = vm.dDrawLine.guid == null ? "bss/ddrawline/save" : "bss/ddrawline/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.dDrawLine),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var guids = getSelectedRows();
			if(guids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "bss/ddrawline/delete",
                    contentType: "application/json",
				    data: JSON.stringify(guids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(guid){
			$.get(baseURL + "bss/ddrawline/info/"+guid, function(r){
                vm.dDrawLine = r.dDrawLine;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});